﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="_Inherits="UI.Views.Account._IdentityProvidersWithClientSideCode" %>*@


// Copyright 2010 Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License"); 
// You may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 

// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
// INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 
// CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
// MERCHANTABLITY OR NON-INFRINGEMENT. 

// See the Apache 2 License for the specific language governing 
// permissions and limitations under the License.
*@

@model ASC.Hrd.HrdRequest

@*Needed for Visual Studio Intellisense*@
@if (false)
{
    <script src="/Scripts/jquery-1.4.4-vsdoc.js" type="text/javascript"></script>
}

@*Using client side script to get the HRD data from ACS*@
<script type="text/javascript">
    $(function () {
        $("#signIn").click(function () {
            //
            // Explicit JSONP callback can be used to do client side caching of identity provider data.
            //
            $.ajax({
                url: "@Html.Raw(Model.GetUrlWithQueryString())",
                dataType: "jsonp",
                success: function (data, textStatus, jqXHR) {
                    $("#main").hide("blind", 500, function () {
                        // Clear the main content
                        $("#main").empty();

                        $('<div id="identity-provider-content">' +
                          '<h2>Sign in using one of the following Identity Providers</h2>' +
                          '<div id="identity-providers"></div></div>').appendTo("#main");

                        for (var i in data) {
                            $(GetIdentityProviderTag(data[i], i)).appendTo("#identity-providers");
                            $("#button" + i + " button").data("signInUrl", data[i].LoginUrl);
                        }
                        //
                        // make buttons jqueryui buttons
                        //
                        $("button").button();

                        //
                        // add click behaviour
                        //
                        $("button").click(function () {
                            window.location = $.data(this, "signInUrl");
                        });
                    });

                    $("#main").show("blind", 750);
                }
            });
            //
            // Stop event bubbling
            //
            return false;
        });
    });

    // Gets the div tag and its content for an identity provider
    function GetIdentityProviderTag(idp, index) {
        return '<div class="identity-provider" id="button' + index + '"><button>' + idp.Name + ' </button></div>';
    }
</script>

<div>
    <a href="" id="signIn">Sign In</a>
</div>


